package com.example.demo;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class messageWallController {
    private List<Message> messageinfo = new ArrayList<Message>();
    @RequestMapping("/getList")
    public List<Message> getList(){
        return messageinfo;
    }

    @RequestMapping(value = "/publish",produces ="appliaction/json")
    public String publish(@RequestBody Message message){
        if(StringUtils.hasLength(message.getFrom())&&StringUtils.hasLength(message.getMessage())&&
        StringUtils.hasLength(message.getTo())){
            messageinfo.add(message);
            return "{\"ok\":1}";
        }
        return "{\"ok\":0}";
    }

}
